package com.qs.eggs.account;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.qs.eggs.Constants;
import com.qs.eggs.R;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Response;

public class ForgetPasswordnextActivity extends Activity implements View.OnClickListener{
    private EditText mima,mima1;
    private Button commit;
    private String phone;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_passwordnext);
        phone=getIntent().getStringExtra("phone");
        initView();
    }
    private void initView(){
        mima=(EditText)findViewById(R.id.et_mima);
        mima1=(EditText)findViewById(R.id.et_mimatwo);
        commit=(Button)findViewById(R.id.commit);

       commit.setOnClickListener(this);
    }
    @Override
    public void onClick(View view){
        switch (view.getId()){
            case R.id.commit:
                tijiao();
                break;
        }
    }
    private void tijiao(){
        String txt = mima.getText().toString();
        String pxt = mima1.getText().toString();
        if(txt.length()==0||pxt.length()==0){
            Toast.makeText(ForgetPasswordnextActivity.this,"密码不能为空",Toast.LENGTH_SHORT).show();
            return;

        }
        if(!txt.equals(pxt)){
            Toast.makeText(ForgetPasswordnextActivity.this, "密码输入不一致",Toast.LENGTH_SHORT ).show();
        }else{
            Map<String, String> map = new HashMap<>();
            map.put("password",mima.getText().toString());
            map.put("phone",phone);
            Gson gson=new Gson();
            String str=gson.toJson(map);
            OkGo.post(Constants.URL_BASE+"register?action=upPassword")
                   .params("data",str)
                    .execute(new StringCallback() {
                        @Override
                        public void onSuccess(String s, Call call, Response response) {
                            System.out.print("修改成功=="+s);
                            if (s.equals("\"true\"")){
                                Toast.makeText(ForgetPasswordnextActivity.this,"密码修改成功",Toast.LENGTH_SHORT).show();
                                ForgetPasswordActivity.instance.finish();
                                ForgetPasswordnextActivity.this.finish();

                            }else {
                                Toast.makeText(ForgetPasswordnextActivity.this,"密码修改失败",Toast.LENGTH_SHORT).show();
                            }
                        }
                    });

        }

    }
}
